package com.yunji.base.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunji.base.dao.ITextRecordDao;
import com.yunji.base.mapper.ITextRecordMapper;
import com.yunji.common.base.BaseDaoImpl;
import com.yunji.common.model.domain.TextRecordDO;
import com.yunji.common.model.dto.TextRecordDTO;
import com.yunji.common.utils.bean.BeanUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class TextRecordDaoImpl extends BaseDaoImpl<ITextRecordMapper, TextRecordDO> implements ITextRecordDao {
    @Override
    public List<TextRecordDO> getPageList(TextRecordDTO dto) {
        return pageList(dto,new LambdaQueryWrapper<TextRecordDO>()
                .eq(BeanUtils.isNotNull(dto.getTextType()),TextRecordDO::getTextType,dto.getTextType())
                .eq(BeanUtils.isNotNull(dto.getTextId()),TextRecordDO::getTextId,dto.getTextId())
                .like(BeanUtils.isNotNull(dto.getTextTitle()),TextRecordDO::getTextTitle,dto.getTextTitle()));
    }

    @Override
    public boolean checkUniqueTextType(Integer textType,Long textId) {
        return lambdaQuery().eq(TextRecordDO::getTextType,textType).notIn(BeanUtils.isNotNull(textId),TextRecordDO::getTextId,textId).exists();
    }
}
